<?php
	/* Pagina que exibe as respostas de um exercicio do usuario */

	session_start();

	include("/var/www/html/vivencias/conexaoBD.php");
	include("/var/www/html/vivencias/verificaRecursosAtivados.php");

	//Inicializando variaveis
	$idFormulario = $_GET['idFormulario'];
	$idUsuario    = $_GET['idUsuario'];
	$i            = 0;
	$k	      = 0;


	//Seleciona o nome do formulario
	$queryNomeFor     = "SELECT nomefor,corrigir FROM formularios WHERE idformulario='".$idFormulario."'";
	$resultadoNomeFor = mysql_query($queryNomeFor,$conexao);
	$objetoNomeFor    = mysql_fetch_object($resultadoNomeFor);

	//Seleciona o nome do usuario
	$queryNomeUser     = "SELECT nome FROM usuarios WHERE idUsuario='".$idUsuario."'";
	$resultadoNomeUser = mysql_query($queryNomeUser,$conexao);
	$objetoNomeUser    = mysql_fetch_object($resultadoNomeUser);

	//Seleciona respostas do usuario e armazena em um vetor
	$queryRespostas     = "SELECT * FROM formulariosRespostas WHERE idUsuario='".$idUsuario."' AND idformulario='".$idFormulario."'";
	$resultadoRespostas = mysql_query($queryRespostas,$conexao);
	while($objetoRespostas = mysql_fetch_object($resultadoRespostas)){
		$respostas[$i] = $objetoRespostas->resposta;
		$idFormularioPerguntas[$i] = $objetoRespostas->idFormularioPerguntas;
		$i++;
	}

	//Verifica se o professor ja corrigiu o exercicio para exibir a correcao
	$queryCorrigido     = "SELECT * FROM formulariosCorrigidos WHERE idformulario='".$idFormulario."' AND idUsuario='".$idUsuario."'";
	$resultadoCorrigido = mysql_query($queryCorrigido,$conexao);
	if($num_result = mysql_num_rows($resultadoCorrigido)){
		$objetoCorrigido    = mysql_fetch_object($resultadoCorrigido);
	}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Experi&ecirc;ncias do Processo de Adoecimento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="vivencias.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('imagens/stt_cadastro2.jpg','imagens/stt_banco2.jpg','imagens/stt_relator2.jpg','imagens/stt_definI2.jpg','imagens/stt_correcao2.jpg')">
<div align="center">
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="10%" align="left" valign="top"><img src="imagens/logo.jpg" width="66" height="53"></td>
                  <td width="90%"><img src="imagens/tit1.jpg" width="612" height="28"></td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr align="left" valign="middle">
                  <td colspan="3" class="nomecurso"><?php echo $_SESSION['nomeCurso'];?></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><a href="index.php"><img src="imagens/sair.gif" width="33" height="19" border="0"></a></td>
                </tr>
                <tr align="left" valign="middle">
                  <td width="25%">&nbsp;</td>
                  <td width="22%">&nbsp;</td>
                  <td width="52%">&nbsp;</td>
                  <td width="0%">&nbsp;</td>
                  <td width="0%">&nbsp;</td>
                  <td width="1%">&nbsp;</td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr align="left" valign="top">
                  <td width="2%" background="imagens/bar_fnd_8.jpg" bgcolor="EBF4F9"><a href="relatorios.htm"><img src="imagens/mn_8.jpg" width="23" height="161" border="0"></a></td>
                  <td width="60%" align="center" bgcolor="f4f1fc">
                    <table width="816" border="0" cellpadding="0" cellspacing="0">
                      <tr align="left" valign="top">
                        <td width="10"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                        <td width="73"><a href="listagemAlunos.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('cadastro','','imagens/stt_cadastro2.jpg',1)"><img src="imagens/stt_cadastro1.jpg" name="cadastro" width="73" height="21" border="0"></a></td>
                        <td width="10"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                        <td width="52"><a href="bancoG.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('banco','','imagens/stt_banco2.jpg',1)"><img src="imagens/stt_banco1.jpg" name="banco" width="52" height="21" border="0"></a></td>
                        <td width="10"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                        <td width="81"><a href="relatorios.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('relatorios','','imagens/stt_relator2.jpg',1)"><img src="imagens/stt_relator1.jpg" name="relatorios" width="81" height="21" border="0"></a></td>
                        <td width="10"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                        <td width="86"><a href="correcao.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('exercicios','','imagens/stt_correcao2.jpg',1)"><img src="imagens/stt_correcao1.jpg" name="exercicios" width="81" height="21" border="0"></a></td>
                        <td width="1"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                        <td width="116"><a href="d.comunica.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('definicoesiniciais','','imagens/stt_definI2.jpg',1)"><img src="imagens/stt_definI1.jpg" name="definicoesiniciais" width="140" height="21" border="0"></a></td>
                        <td width="117"><img src="imagens/pix_cor7b.gif" width="84" height="5"></td>
                      </tr>
                      <tr align="left" valign="top">
                        <td colspan="11"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td width="1%"><img src="imagens/pix_cor7b.gif" width="10" height="5"></td>
                              <td width="41%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="3%">&nbsp;</td>
                              <td width="19%">&nbsp;</td>
                            </tr>
                          </table></td>
                      </tr>
                    </table>
                    <table width="95%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                      <tr bgcolor="f4f1fc" class="texttab">
                        <td align="left" valign="middle" class="titprincipal"><a href="corrigeExerciciosUsuarios.php?idFormulario=<?php echo $idFormulario;?>" class="miudo">Voltar</a></td>
                        <td align="right" valign="middle" class="miudo">Visualizar
                          impress&atilde;o</td>
                      </tr>
                      <tr align="center" valign="middle" bgcolor="ddd9e9" class="texttab">
                        <td colspan="2" class="texto2"> <div align="center">
                            <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                              <tr>
                                <td width="100%" bgcolor="9786c6" class="titprincipal"><span class="titvermelho">CORRE&Ccedil;&Atilde;O</span><span class="ativomenor">
                                  dos</span> <span class="ativomenor">exerc&iacute;cios
                                  dos alunos</span></td>
                              </tr>
                              <tr>
                                <td bgcolor="a99ec6" class="titprincipal"><span class="ativo"><?php echo $objetoNomeFor->nomefor;?></span></td>
                              </tr>
                              <tr>
                                <td bgcolor="a99ec6" class="texto2">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                                    <tr align="center" valign="middle" bgcolor="f4f1fc" class="texto">
                                      <td align="left" bgcolor="a99ec6"><span class="ativo"><strong><a href="geral.carol.htm" class="ativo"><?php echo $objetoNomeUser->nome;?></a></strong></span></td>
                                    </tr>
				    <?php
						//Seleciona as perguntas do formulario
						$query     = "SELECT * FROM formulariosPerguntas WHERE idFormulario='".$idFormulario."'";
						$resultado = mysql_query($query,$conexao);
						while($objeto = mysql_fetch_object($resultado)){
							//Armazena a resposta da pergunta selecionada no while para exibi-la
							for($j = 0;$j < count($respostas);$j++){
								if($objeto->idFormularioPerguntas == $idFormularioPerguntas[$j]){
									if($objeto->idTipoPergunta!='4'){
										$resposta = $respostas[$j];
										$j = count($respostas) + 1;
									}else{
										$respostaMultEscolha[$k] = $respostas[$j];
										$k++;
									}
								}else{
									if($objeto->idTipoPergunta!='4'){
										$resposta = '';
									}
								}
							}
				    ?>
                                    <tr align="center" valign="middle" bgcolor="f4f1fc" class="texto">
                                      <td align="right" bgcolor="ddd9e9"> <p align="left" class="texto"><span class="texto2"><strong>
                                      		<?php

                                      				$pergunta	= $objeto->pergunta;
													$enter	= array("\r\n", "\n", "\r");
												    $br	= '<br />';
													$pergNova = str_replace($enter, $br, $pergunta);

                                   		            echo $pergNova;
                                      		?></strong><br>
                                          </span> </p></td>
                                    </tr>
                                    <tr align="center" valign="middle" bgcolor="f4f1fc" class="texto">
                                      <td align="left" bgcolor="ddd9e9"> <p class="texto2"><strong>Resposta</strong><strong><br>
				      <?php
						//Discursiva Longa
						if($objeto->idTipoPergunta == 2){
				      ?>
                                          <textarea name="textarea2" cols="80" rows="15" readonly><?php echo $resposta;?></textarea>
					    <tr align="center" bgcolor="#38708F" class="texttab">
                                              <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                            </tr>
				      <?php
						//Discursiva Curta
						}else if($objeto->idTipoPergunta == 1){
				      ?>
					 <textarea name="discursivaCurta" cols="80" rows="4" readonly><?php echo $resposta;?></textarea>
	                                 <tr align="center" bgcolor="#38708F" class="texttab">
                                            <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                         </tr>
				      <?php
						//Caixa de Selecao
						}else if($objeto->idTipoPergunta == '0'){
							echo '<select name="caixaSelecao" disabled>';
							echo '<option value="-1"></option>';
							$queryCS     = "SELECT * FROM formulariosAlternativas WHERE idFormularioPerguntas='".$objeto->idFormularioPerguntas."'";
							$resultadoCS = mysql_query($queryCS,$conexao);
							while($objetoCS = mysql_fetch_object($resultadoCS)){
								if($objetoCS->alternativa == $resposta){
									$selected = 'selected';
								}else{
									$selected = '';
								}

				      ?>
				      <option value="<?php echo $objetoCS->idFormulariosAlternativas;?>" <?php echo $selected;?> readonly><?php echo $objetoCS->alternativa;?></option>

				      <?php } ?><!--Fechando o while da caixa de selecao -->
				      </select>
				      <tr align="center" bgcolor="#38708F" class="texttab">
                                         <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                      </tr>
				      <?php
						//Objetiva SimNao
						}else if($objeto->idTipoPergunta == 3){
							if($resposta == 'Sim'){
								$checkedSim = 'checked';
								$checkedNao = '';
							}else if($resposta == ''){
								$checkedSim = '';
								$checkedNao = '';
							}else{ //se a resposta for Nao
								$checkedSim = '';
								$checkedNao = 'checked';
							}
 			              ?>
						<label><span class="texto2">
						<input type="radio" name="objetivaSim" value="Sim" <?php echo $checkedSim;?> readonly><strong>Sim</span></label>
                      				<span class="texto2"><br>
                     			        <label><input type="radio" name="objetivaNao" value="N&atilde;o" <?php echo $checkedNao;?> readonly><strong>N&atilde;o</label>
						<tr align="center" bgcolor="#38708F" class="texttab">
	                                          <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
        	                                </tr>

				      <?php
						//Selecao Unica
						}else if($objeto->idTipoPergunta == 5){
							$querySU = "SELECT * FROM formulariosAlternativas WHERE idFormularioPerguntas='".$objeto->idFormularioPerguntas."'";
							$resultadoSU = mysql_query($querySU,$conexao);
							while($objetoSU = mysql_fetch_object($resultadoSU)){
								if($objetoSU->alternativa == $resposta){
									$checked = 'checked';
								}else{
									$checked = '';
								}

				      ?>
						<label>
						<input type="radio" name="selecaoUnica" <?php echo $checked;?> value="<?php echo $objetoSU->idFormulariosAlternativas;?>" readonly>
						<?php echo $objetoSU->alternativa;?>
						</label><br>
				      <?php } ?><!--Fechando while da selecao unica-->
						<tr align="center" bgcolor="#38708F" class="texttab">
                                        	 <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                      		</tr>
				      <?php
						//Multipla Escolha
						}else if($objeto->idTipoPergunta == 4){
							$queryME = "SELECT * FROM formulariosAlternativas WHERE idFormularioPerguntas='".$objeto->idFormularioPerguntas."'";
							$resultadoME = mysql_query($queryME,$conexao);
							while($objetoME = mysql_fetch_object($resultadoME)){
								//Verificando quais alternativas o usuario respondeu
								for($k = 0;$k < count($respostaMultEscolha);$k++){
									if($objetoME->alternativa == $respostaMultEscolha[$k]){

				      ?>
										<input type="checkbox" name="multiplaEscolha" value="<?php echo $objetoME->idFormulariosAlternativas;?>" checked readonly>
                      								<label><?php echo $objetoME->alternativa;?></label><br>

							<?php
										$k = count($respostaMultEscolha) + 1;
										$naoRespondeuAlternativa = 0;
									}else{
										$naoRespondeuAlternativa = 1;
									}
								}

								//Se o usuario nao respondeu aquela alternativa
								if($naoRespondeuAlternativa){
							?>

									<input type="checkbox" name="multiplaEscolha" value="<?php echo $objeto2->idFormulariosAlternativas;?>" readonly>
                      							<label><?php echo $objetoME->alternativa;?></label><br>
				      			<?php }} ?><!--Fechando while e o if da multipla escolha-->

						<tr align="center" bgcolor="#38708F" class="texttab">
                                        	 <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                      		</tr>
				      <?php
						//Arquivos
						}else if($objeto->idTipoPergunta == 6){
				      ?>
						<tr align="center" valign="middle" bgcolor="f4f1fc" class="texto">
                                     	           <td align="left" bgcolor="ddd9e9">
						     <input type="button" name="Baixar" value="Baixar Arquivo" onClick="window.open('<?php echo $resposta;?>')">
						  </td>
						</tr>

				      	 <?php } ?><!--Fechando if do arquivo-->

                                          </strong> </p></td>
                                    </tr><?php } ?><!--Fechando while que exibe perguntas -->

                                    <tr align="center" bgcolor="#38708F" class="texttab">
                                      <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2">&nbsp;</td>
                                    </tr>
				    <!--Verificando se o professor optou por corrigir o formulario-->
				    <?php if($objetoNomeFor->corrigir){ ?>
				    <form action="insereNotaExercicio.php" method="post">
                                    <tr align="center" bgcolor="#38708F" class="texttab">
                                      <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2"><div align="left" class="branco"><span class="texto2"><strong>Coment&aacute;rio
                                          do Professor</strong></span><br>
                                          <strong>
                                          <textarea name="comentario" cols="80" rows="10" <?php if($num_result){ echo 'readonly';}?>><?php if($num_result){ echo $objetoCorrigido->comentario;}?></textarea>
                                          </strong> <br>
                                        </div></td>
                                    </tr>
                                    <tr align="center" bgcolor="#38708F" class="texttab">
                                      <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2"><div align="left" class="branco"><span class="texto2"><strong>Nota<br>
                                          <input name="nota" type="text" size="5" value="<?php echo $objetoCorrigido->nota;?>" <?php if($num_result){ echo 'readonly';}?>>
                                          </strong></span></div></td>
                                    </tr>
				    <input type="hidden" name="idUsuario" value="<?php echo $idUsuario;?>">
				    <input type="hidden" name="idFormulario" value="<?php echo $idFormulario;?>">
                                    <!--<tr align="center" bgcolor="#38708F" class="texttab">
                                      <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2"><strong>Permitir
                                        que o aluno reenvie?
                                        <input type="radio" name="radiobutton" value="radiobutton">
                                        Sim
                                        <input type="radio" name="radiobutton" value="radiobutton">
                                        N&atilde;o</strong></td>
                                    </tr>-->
				    <?php if(!$num_result){ ?>
                                    <tr align="center" bgcolor="#38708F" class="texttab">
                                      <td align="left" valign="middle" bgcolor="ddd9e9" class="texto2"><input type="submit" name="corrige" value="Enviar Corre&ccedil;&atilde;o"></td>
                                    </tr>
				    <?php } ?>
				    </form>
				    <?php } ?><!--Fechando o if de correcao do form -->
                                  </table>
                                </td>
                              </tr>
                            </table>
                          </div></td>
                      </tr>
                    </table>
                    <p>&nbsp;</p></td>
                  <td width="0%" align="right" background="imagens/bar_fnd_7.jpg"><a href="info.php"><img src="imagens/mn_7.jpg" width="23" height="137" border="0"></a>
                  </td>
                  <td width="8%" align="right" background="imagens/bar_fnd_6.jpg"><a href="esppess.php"><img src="imagens/mn_6.jpg" width="23" height="156" border="0"></a>
                  </td>
                  <td width="4%" align="right" background="imagens/bar_fnd_5.jpg"><a href="comunicacao.php"><img src="imagens/mn_5.jpg" width="23" height="146" border="0"></a>
                  </td>
                  <td width="5%" align="right" background="imagens/bar_fnd_4.jpg"><a href="banco.php"><img src="imagens/mn_4.jpg" width="23" height="219" border="0"></a>
                  </td>
                  <td width="4%" align="right" background="imagens/bar_fnd_3.jpg"><a href="ferramentasTrabalho.php"><img src="imagens/mn_3.jpg" width="23" height="249" border="0"></a>
                  </td>
                  <td width="2%" align="right" background="imagens/bar_fnd_2.jpg"><a href="conteudo.php"><img src="imagens/mn_2.jpg" width="23" height="113" border="0"></a></td>
                  <td width="15%" align="right" background="imagens/bar_fnd_1.jpg" bgcolor="F1FEF9">
                    <p><a href="principal.php"><img src="imagens/mn_1.jpg" width="23" height="103" border="0"></a></p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
</body>
</html>
